

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>家居家具管理系统</title>

    <!-- begin::global styles -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/bundle.css" type="text/css">
    <!-- end::global styles -->

    <!-- begin::dropzone -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/dropzone/dropzone.css" type="text/css">
    <!-- begin::dropzone -->

    <!-- begin::select2 -->
    <link rel="stylesheet" href="${APP_PATH}/assets/vendors/select2/css/select2.min.css" type="text/css">
    <!-- end::select2 -->

    <!-- begin::custom styles -->
    <link rel="stylesheet" href="${APP_PATH}/assets/css/app.css" type="text/css">
    <link rel="stylesheet" href="${APP_PATH}/assets/css/custom.css" type="text/css">
    <!-- end::custom styles -->

</head>
<body>

<!-- begin::page loader-->
<div class="page-loader">
    <div class="page-loader">
        <div class="spinner-border text-primary"></div>
        <span>加载中 ...</span>
    </div>
</div>
<!-- end::page loader -->

<!-- begin::navigation -->
<jsp:include page="/WEB-INF/jsps/Manager/common/navigation.jsp"/>
<!-- end::navigation -->

<!-- begin::top -->
<jsp:include page="/WEB-INF/jsps/Manager/common/top.jsp"/>
<!-- end::top -->

<!-- begin::main content -->
<main class="main-content">

    <div class="container-fluid">

        <!-- begin::page header -->
        <div class="page-header d-md-flex justify-content-between align-items-center">
            <h4>${requestScope.kindsType.ktname}</h4>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb m-t-0">
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toManager">首页</a></li>
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toMyGoods">我的商品</a></li>
                    <li class="breadcrumb-item"><a href="${APP_PATH}/toKindsType?kid=${requestScope.kinds.kid}">${requestScope.kinds.kname}</a></li>
                    <li class="breadcrumb-item active" aria-current="page">${requestScope.kindsType.ktname}</li>
                </ol>
            </nav>
        </div>
        <!-- end::page header -->

        <div class="card-group">
            <div class="card">
                <img src="${APP_PATH}/${requestScope.kindsType.ktface}" class="card-img-top" alt="...">
            </div>
        </div>

        <div class="card-group">
            <div class="card">
                <div class="card-body">

                    <div style="float: left; margin-right: 30px; margin-top: 5px;" class="custom-control custom-switch custom-checkbox-warning">
                        <input type="checkbox" class="custom-control-input" id="customSwitch">
                        <label class="custom-control-label" for="customSwitch">反/全选</label>
                    </div>
                    <button onclick="toInsert()" style="float: left; margin-right: 20px;" type="button" class="btn btn-primary"><i class='ti-plus  m-r-10'></i> 新增商品</button>
                    <button onclick="batchSetCondition(1)" style="float: left; margin-right: 20px;" type="button" class="btn btn-info"><i class='ti-shopping-cart-full  m-r-10'></i> 批量上市</button>
                    <button onclick="batchSetCondition(0)" style="float: left; margin-right: 20px;" type="button" class="btn btn-secondary"><i class='ti-shopping-cart  m-r-10'></i> 批量下架</button>
                    <button onclick="batchDelete()" style="float: left; margin-right: 20px;" type="button" class="btn btn-danger"><i class='ti-trash  m-r-10'></i> 批量删除</button>


                </div>
            </div>
        </div>


        <div class="card">
            <div class="card-body">
                <ul class="nav nav-tabs m-b-30" id="myTab" role="tablist">
                    <li class="nav-item">
                        <a id="allFurniture" class="nav-link active" data-toggle="tab" href="#all" role="tab" aria-controls="all"
                           aria-selected="true"><span>全部商品</span><span id="allBadge" style="margin-left: 5px;" class="badge badge-success"></span></a>
                    </li>
                    <li class="nav-item">
                        <a id="onSaleFurniture" class="nav-link" data-toggle="tab" href="#onSale" role="tab" aria-controls="onSale"
                           aria-selected="false"><span>在售商品</span><span id="onSaleBadge" style="margin-left: 5px;" class="badge badge-info"></span></a>
                    </li>
                    <li class="nav-item">
                        <a id="offSaleFurniture" class="nav-link" data-toggle="tab" href="#offSale" role="tab" aria-controls="offSale"
                           aria-selected="false"><span>下架商品</span><span id="offSaleBadge" style="margin-left: 5px;" class="badge badge-secondary"></span></a>
                    </li>
                    <li class="nav-item">
                        <a id="vacancyFurniture" class="nav-link" data-toggle="tab" href="#vacancy" role="tab" aria-controls="vacancy"
                           aria-selected="false"><span>库存空缺</span><span id="vacancyBadge" style="margin-left: 5px;" class="badge badge-danger"></span></a>
                    </li>
                </ul>


                <div class="tab-content" id="myTabContent">
                    <div class="tab-pane fade show active" id="all" role="tabpanel" aria-labelledby="home-tab">
                        <jsp:include page="/WEB-INF/jsps/Manager/furniture/all.jsp"/>
                    </div>
                    <div class="tab-pane fade" id="onSale" role="tabpanel" aria-labelledby="profile-tab">
                        <jsp:include page="/WEB-INF/jsps/Manager/furniture/onSale.jsp"/>
                    </div>
                    <div class="tab-pane fade" id="offSale" role="tabpanel" aria-labelledby="contact-tab">
                        <jsp:include page="/WEB-INF/jsps/Manager/furniture/offSale.jsp"/>
                    </div>
                    <div class="tab-pane fade" id="vacancy" role="tabpanel" aria-labelledby="contact-tab">
                        <jsp:include page="/WEB-INF/jsps/Manager/furniture/vacancy.jsp"/>
                    </div>
                </div>

            </div>
        </div>

        <!-- begin::bottom -->
        <div class="card-group">
            <jsp:include page="/WEB-INF/jsps/Manager/common/bottom.jsp"/>
        </div>
        <!-- end::bottom -->


    </div>




</main>
<!-- end::main content -->


<!-- begin::global scripts -->
<script src="${APP_PATH}/assets/vendors/bundle.js"></script>
<!-- end::global scripts -->

<!-- begin::dropzone -->
<script src="${APP_PATH}/assets/vendors/dropzone/dropzone.js"></script>
<!-- end::dropzone -->

<!-- begin::select2 -->
<script src="${APP_PATH}/assets/vendors/select2/js/select2.min.js"></script>
<script src="${APP_PATH}/assets/js/examples/select2.js"></script>
<!-- end::select2 -->

<!-- begin::custom scripts -->
<script src="${APP_PATH}/assets/js/custom.js"></script>
<script src="${APP_PATH}/assets/js/app.js"></script>
<!-- end::custom scripts -->


</body>
</html>

<script>
    var target = null;
    $(function () {
        $("#${requestScope.target}").click();
        getTarget();
        $("#customSwitch").change(function () {
            if($(this).prop("checked")){
                $("."+target).addClass("isSelected").children(".delete").fadeOut("fast","linear");
            }else{
                $("."+target).removeClass("isSelected").children(".delete").fadeIn("fast","linear");
            }
        });

        $(".nav-link").each(function () {
            $(this).click(function () {
                $("#customSwitch").prop("checked",false);
                $("."+target).removeClass("isSelected").children(".delete").fadeIn("fast","linear");
            }).mouseleave(function () {
                getTarget();
            });
        });

    });

    function batchSetCondition(val) {
        var batchFid = new Array();
        $(".isSelected").each(function (i) {
            batchFid[i] = $(this).attr("id");
        });
        if(batchFid.length > 0){
            $.ajax({
                url : "${APP_PATH}/furniture/setCondition",
                method : "POST",
                data : {
                    batchFid : batchFid,
                    val : val
                },
                success : function (result) {
                    if(!result.success){
                        swal("您选择的商品缺失重要信息,无法批量上市！.", {icon: "error"});
                    }
                },
                complete : function () {
                    renovate();
                }
            });
        }
    }

    function batchDelete() {
        var batchFid = new Array();
        $(".isSelected").each(function (i) {
            batchFid[i] = $(this).attr("id");
        });
        var data = {
            batchFid : batchFid
        };
        swal({
            title: "确定要删除吗?",
            icon: "warning",
            buttons: ["算了", "就要"],
            dangerMode: true
        }).then((willDelete) => {
            if (willDelete) {

          if(batchFid.length > 0){
              $.ajax({
                  url: "${APP_PATH}/furniture/deleteFurnitureBatch",
                  method: 'POST',
                  data:data,
                  success: function (result) {
                      if (result.success) {
                          swal("删除成功！", {
                                  icon: "success"
                              }
                          );
                          renovate();
                      }else{
                          swal("选中商品中存在交易信息，无法删除！", {
                                  icon: "error"
                              }
                          );
                      }
                  }
              });
          }

            } else {
                swal("您取消了删除.", {
            icon: "info"
        });
    }
    });

    }

    function getTarget() {
         target = $("#myTab a[class *= active]").attr("id");
    }

    function renovate() {
        $("#customSwitch").prop("checked",false);
            allFurnitureCards(allPageNo);
            onSaleFurnitureCards(onSalePageNo);
            offSaleFurnitureCards(offSalePageNo);
            vacancyFurnitureCards(vacancyPageNo);
    }


    //跳转到insert界面
    function toInsert() {
        window.location.href="${APP_PATH}/toFurniture_Insert?kid=${requestScope.kinds.kid}&ktid=${requestScope.kindsType.ktid}";
    }

    function toFurnitureDetail(fid,target,pageNo) {
        window.location.href="${APP_PATH}/toFurniture_Detail?kid=${requestScope.kinds.kid}&ktid=${requestScope.kindsType.ktid}&fid="+fid+"&target="+target+"&pageNo="+pageNo;
    }

    function myDelete(id) {
        var data = {
            _method: 'DELETE',
            fid: id
        };

        swal({
            title: "确定要删除吗?",
            icon: "warning",
            buttons: ["算了", "就要"],
            dangerMode: true
        }).then((willDelete) => {
            if (willDelete) {

                $.ajax({
                    url: "${APP_PATH}/furniture/deleteFurniture/"+id,
                    method: 'POST',
                    data:data,
                    success: function (result) {
                        if (result.success) {
                            swal("删除成功！", {
                                    icon: "success"
                                }
                            );
                            renovate();
                        }else{
                            swal("该商品已存在交易信息，无法删除！", {
                                    icon: "error"
                                }
                            );
                        }
                    }
                });

            } else {
                swal("您取消了删除.", {
            icon: "info"
        });
    }
    });

    }
</script>


